package com.tgr.shortLink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tgr.shortLink.admin.common.convention.result.Result;
import com.tgr.shortLink.admin.remote.ShortLinkActualRemoteService;
import com.tgr.shortLink.admin.remote.ShortLinkRemoteService;
import com.tgr.shortLink.admin.remote.dto.req.LinkStatsAccessRecordReqDTO;
import com.tgr.shortLink.admin.remote.dto.req.LinkStatsReqDTO;
import com.tgr.shortLink.admin.remote.dto.resp.LinkStatsAccessRecordRespDTO;
import com.tgr.shortLink.admin.remote.dto.resp.LinkStatsRespDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述：
 * 作者：小陶不慌张
 * 文件：LinkStatsController
 * 日期：2024/1/29 17:06
 */
@RestController(value = "linkStatsControllerAdmin")
@RequiredArgsConstructor
public class LinkStatsController {
    //远程调用时不能使用private final ShortLinkRemoteService shortLinkRemoteService;
    //TODO 查询会报错的原因
    ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService(){
    };
    private final ShortLinkActualRemoteService shortLinkActualRemoteService;

    /**
     * 获取单个短链接监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats")
    public Result<LinkStatsRespDTO> shortLinkStats(LinkStatsReqDTO requestParam) {
        return shortLinkActualRemoteService.oneShortLinkStats(requestParam.getFullShortUrl(), requestParam.getGid(), requestParam.getStartDate(), requestParam.getEndDate());
    }
    /**
     * 单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats/access-record")
    public Result<Page<LinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(LinkStatsAccessRecordReqDTO requestParam) {
        return shortLinkActualRemoteService.linkStatsAccessRecord(requestParam);
    }


}
